package com.kehongborui.spring.controller;

import com.kehongborui.spring.model.UserModel;
import com.kehongborui.spring.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;

/**
 * @author zhang peng yang ming
 * @create 2018-08-07 20:56
 */
@Controller
public class HelloController {
    @Autowired
    private LoginService loginService;

//    @ModelAttribute("attributeName")
//    public String preHandler(@RequestParam String abc) {
//        return abc;
//    }

    @ModelAttribute
    public UserModel preHandler(String username,  String password) {
        return loginService.login(username, password);
    }
    @RequestMapping(value = "/hello")
    public String hello(@ModelAttribute("userModel") UserModel userModel) {
        return "hello";
    }

//    @ModelAttribute
//    public void preHandler(@RequestParam String abc, Model model) {
//        model.addAttribute("attributeName", abc);
//    }

    @RequestMapping(value = "/hello2")
    public String hello2() {
        return "hello";
    }
}
